package cascade.components
{
	import cascade.model.Page;
	
	import mx.collections.ArrayCollection;
	import mx.controls.treeClasses.DefaultDataDescriptor;

	public class NodeDragDataDescriptor extends DefaultDataDescriptor
	{
		
		public var isShowingFeedback:Boolean;
		
		/**
		 *  @inheritDoc
		 */
		public override function getChildren(node:Object, model:Object = null):ICollectionView
		{
			return Page.getChildren(node as Page);
		}
	
		/**
		 *  @inheritDoc
		 */
		public override function isBranch(node:Object, model:Object=null):Boolean {
			if (isShowingFeedback)
				return true;
			
			return Page.getChildren(node as Page).length > 0;
		}
	
		/**
		 *  @inheritDoc
		 */
		public override function addChildAt(parent:Object, newChild:Object, index:int, model:Object = null):Boolean
		{
			// TODO, make it happen cap'n (parent is null for top-level nodes 
			
			return false;
		}
	
		/**
		 *  @inheritDoc
		 */
		public override function removeChildAt(parent:Object, child:Object, index:int, model:Object = null):Boolean
		{
			// TODO, make it happen cap'n
			
			return false;
		}
		
		/**
		 *  @inheritDoc
		 */
		public override function getHierarchicalCollectionAdaptor(hierarchicalData:ICollectionView, uidFunction:Function, openItems:Object, model:Object = null):ICollectionView
		{
			return null;//new HierarchicalCollectionView(hierarchicalData, this, uidFunction, openItems);
		}
		
		/**
		 *  @inheritDoc
		 */
		public override function getNodeDepth(node:Object, iterator:IViewCursor, model:Object = null):int
		{
			if (node == iterator.current)
				return HierarchicalViewCursor(iterator).currentDepth;
			return -1;
		}
	
		/**
		 *  @inheritDoc
		 */
		public override function getParent(node:Object, collection:ICollectionView, model:Object = null):Object
		{
			return HierarchicalCollectionView(collection).getParentItem(node);
		}
		
		
		
		
		
	}
}